package com.quanyou.utils;

import java.text.SimpleDateFormat;

/**
 * Created by Thinkpad on 2016/4/21.
 */
public class ValidUtil {

    public static boolean isMobile(String mobile) {
        if (mobile == null || mobile.trim().length() == 0) {
            return false;
        }
        if (!mobile.matches("(1[3-9])\\d{9}")) {
            return false;
        }
        return true;
    }

    public static boolean isIdCard(String idCard) {
        if (idCard == null || idCard.trim().length() == 0) {
            return false;
        }
        if (!idCard.matches("[1-9]\\d{5}((1[89]|20)\\d{2})(0[1-9]|1[0-2])(0[1-9]|[12]\\d|3[01])\\d{3}[\\dxX]")) {
            return false;
        }
        return true;
    }

    public static boolean isEmail(String email) {
        if (email == null || email.trim().length() == 0) {
            return false;
        }
        if (!email.matches("[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+")) {
            return false;
        }
        return true;
    }

    public static boolean isDate(String time,String formatStr) {
        if (Utility.isBlank(time) || Utility.isBlank(formatStr)) {
            return false;
        }
        try {
            SimpleDateFormat format = new SimpleDateFormat(formatStr);
            format.parse(time);
        } catch (Exception e) {
            return false;
        }
        return true;
    }

    public static boolean isNumber(String numberStr) {
        if (Utility.isBlank(numberStr)) {
            return false;
        }
        if (!numberStr.matches("\\d+(.\\d+)?")) {
            return false;
        }
        return true;
    }
}
